package cn.lovezsm.bjcjweb.controller;

import cn.lovezsm.bjcjbase.bean.GridMap;
import cn.lovezsm.bjcjbase.bean.LocationResult;
import cn.lovezsm.bjcjbase.util.SpringUtils;
import cn.lovezsm.bjcjdao.LocationResultCache;
import cn.lovezsm.bjcjweb.bean.LocationInfo;
import cn.lovezsm.locationsystem.handler.LocationSystemHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("api/location")
public class LocationSysController {
    @Autowired
    LocationResultCache locationResultCache;

    @Autowired
    LocationSystemHandler handler;

    @GetMapping("getGridMapData")
    public GridMap getGridMapData(){

        return SpringUtils.getBean(GridMap.class);
    }
    @GetMapping("startLocation")
    public boolean startLocation(){
        return handler.startLocation();
    }

    @GetMapping("stopLocation")
    public void stopLocation(){
        handler.stopLocation();
    }

    @GetMapping("getLocationInfo")
    public LocationInfo getLocationInfo(){
        LocationInfo locationInfo = new LocationInfo();
        Map<String, Object> all = locationResultCache.getAll();

        for (Map.Entry<String,Object> entry:all.entrySet()){
            locationInfo.getLocationResultMap().put(entry.getKey(), (LocationResult) entry.getValue());
        }

        return locationInfo;
    }
}
